﻿using System.Collections.Generic;
using TMPro;
using Unity.VisualScripting;

namespace Yzq.BLL
{
    // 定义一个枚举，列出所有的设置项
    public enum SettingKey
    {
        ServerIP,      // string
        Port,          // int
        SampleRate,    // int
        ContextNum,    // int 
        LLmsModel,     // string -- 
        BkgImage,      // string -- path
        AudioSavePath, // string -- path
    }
    public static class SettingsSystem 
    {
        private static Dictionary<SettingKey, string> identifiers = new Dictionary<SettingKey, string>()
        {
            { SettingKey.ServerIP, "server_ip" },
            { SettingKey.Port, "port" },
            { SettingKey.SampleRate, "sample_rate" },
            { SettingKey.ContextNum, "context_num" },
            { SettingKey.LLmsModel, "llms_model" },
            { SettingKey.BkgImage, "bkg_image" },
            { SettingKey.AudioSavePath, "audio_save_path" }
        };

        private static Dictionary<SettingKey, ISettingItem> settings = new Dictionary<SettingKey, ISettingItem>();

        // 使用枚举而不是字符串作为键来添加设置
        private static void AddSetting<T>(SettingKey key, T defaultValue, TMP_InputField inputField)
        {
            settings.Add(key, new SettingItem<T>(identifiers[key], defaultValue, inputField));
        }

        // 公开获取设置值的方法
        public static object GetSettingValue(SettingKey key)
        {
            if (settings.TryGetValue(key, out ISettingItem component))
            {
                return component.GetValue();
            }
            throw new KeyNotFoundException($"No setting found with key {key}.");
        }

        public static string GetSettingStr(SettingKey key)
        {
            if (settings.TryGetValue(key, out ISettingItem component))
            {
                return component.GetStringValue();
            }
            throw new KeyNotFoundException($"No setting found with key {key}.");
        }

    }
}
